package com.qs.home.ui.activity;

import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qs.base.base.BaseMyActivity;
import com.qs.base.router.RouterActivityPath;
import com.qs.home.BR;
import com.qs.home.R;
import com.qs.home.databinding.HomeIdentifyResultsBinding;
import com.qs.home.entity.TextResultEntity;
import com.qs.home.ui.VM.IdentifyResultsItemViewModel;
import com.qs.home.ui.VM.IdentifyResultsViewModel;

import java.util.List;

import me.goldze.mvvmhabit.utils.StringUtils;

/**
 * 识别结果
 *
 * @Author ltzz
 * @Date 2019/8/15
 */
@Route(path = RouterActivityPath.Home.IDENTIFY_RESULTS)
public class IdentifyResultsActivity extends BaseMyActivity<HomeIdentifyResultsBinding, IdentifyResultsViewModel> {
    //识别结果数据
    @Autowired()
    String textResults;

    @Override
    protected boolean statusBarDarkFont() {
        return true;
    }

    @Override
    protected View titleLayout() {
        return null;
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.home_identify_results;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding.head.setAutoFinish(this);
        binding.head.setTitleLeftText("识别结果");

        if (!StringUtils.isTrimEmpty(textResults)) {
            Gson gson = new Gson();
            try {
                List<TextResultEntity> textResultList = gson.fromJson(textResults, new TypeToken<List<TextResultEntity>>() {
                }.getType());
                for (int i = 0; i < textResultList.size(); i++) {
                    viewModel.observableList.add(new IdentifyResultsItemViewModel(viewModel, textResultList.get(i)));
                }
            } catch (Exception e) {

            }
        }
    }
}
